package fi.profecons.csswindows.toolkit;

import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;

public class BufferImage extends Image {

	private BufferedImage buffer;

	private File file;

	public BufferedImage getBuffer() {
		return this.buffer;
	}

	public void load(File f) {
		file = f;
		try {
			if (f.exists()) {
				buffer = ImageIO.read(f);
				setBuffer(buffer);
				String source = "?action=IMAGE_FETCH&image_id=" + getId();
				setSource(source, String.valueOf(System.currentTimeMillis()));
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
	}

	public void setBuffer(BufferedImage buffer) {
		setSize(buffer.getWidth(), buffer.getHeight());
		this.buffer = buffer;
	}

}
